package leetcode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @创建人 MBY381
 * @创建时间 2022/3/25 15:51
 * @描述 暂无
 */
public class Solution30 {
    public static List<Integer> findSubstring(String s, String[] words) {
        List<Integer> ans = new ArrayList<>();
        if (s.length() == 0 || words.length == 0) {
            return ans;
        }
        ArrayList<String> wordSet = new ArrayList<>(Arrays.asList(words));
        int length = words.length;
        int wordlen = words[0].length();
        for (int i = 0; i <= s.length() - length * wordlen; i++) {
//            System.out.println("i此时到了："+i);
            int tag = 0;
            for (int j = 0; j < length; j++) {
                int start = i + j * wordlen;
                String temp = s.substring(start, start + wordlen);
                if (wordSet.contains(temp)) {
                    tag++;
                    wordSet.remove(temp);
//                    System.out.println("i:"+i+"j:"+j+"  wordSet此时为："+wordSet);
                } else {
                    break;
                }
            }
            reFullSet(wordSet, words);
            if (tag == length) {
                ans.add(i);
            }
        }
        return ans;
    }

    public static void reFullSet(ArrayList<String> arr, String[] words) {
        arr.clear();
        arr.addAll(Arrays.asList(words));
    }

    public static void main(String[] args) {
        String[] temp = new String[]{"word", "good", "best", "good"};
        System.out.println(findSubstring("wordgoodgoodgoodbestword", temp));
        List<Integer> ans = new ArrayList<>();
        ans.add(1);
        ans.add(1);
        ans.add(3);
        System.out.println(ans);
        Integer inq = 1;
        ans.remove(inq);
        System.out.println(ans);
    }
}
